package com.codeplex.tdmg4mc;

import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderGearHook extends Render
{
    private static final ResourceLocation arrowTextures = new ResourceLocation("textures/entity/arrow.png");
	public void doRenderTDMGHock(EntityGearHook hook, double par2, double par4, double par6, float par8, float par9)
	{
        Tessellator ts = Tessellator.instance;
		{
	        this.bindTexture(arrowTextures);
	        GL11.glPushMatrix();
	        GL11.glTranslatef((float)par2, (float)par4, (float)par6);
	        GL11.glRotatef(hook.prevRotationYaw + (hook.rotationYaw - hook.prevRotationYaw) * par9 - 90.0F, 0.0F, 1.0F, 0.0F);
	        GL11.glRotatef(hook.prevRotationPitch + (hook.rotationPitch - hook.prevRotationPitch) * par9, 0.0F, 0.0F, 1.0F);
	        byte var11 = 0;
	        float var12 = 0.0F;
	        float var13 = 0.5F;
	        float var14 = (float)(0 + var11 * 10) / 32.0F;
	        float var15 = (float)(5 + var11 * 10) / 32.0F;
	        float var16 = 0.0F;
	        float var17 = 0.15625F;
	        float var18 = (float)(5 + var11 * 10) / 32.0F;
	        float var19 = (float)(10 + var11 * 10) / 32.0F;
	        float var20 = 0.05625F;
	        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
	        
	        GL11.glRotatef(45.0F, 1.0F, 0.0F, 0.0F);
	        GL11.glScalef(var20, var20, var20);
	        GL11.glTranslatef(-4.0F, 0.0F, 0.0F);
	        GL11.glNormal3f(var20, 0.0F, 0.0F);
	        ts.startDrawingQuads();
	        ts.addVertexWithUV(-7.0D, -2.0D, -2.0D, (double)var16, (double)var18);
	        ts.addVertexWithUV(-7.0D, -2.0D, 2.0D, (double)var17, (double)var18);
	        ts.addVertexWithUV(-7.0D, 2.0D, 2.0D, (double)var17, (double)var19);
	        ts.addVertexWithUV(-7.0D, 2.0D, -2.0D, (double)var16, (double)var19);
	        ts.draw();
	        GL11.glNormal3f(-var20, 0.0F, 0.0F);
	        ts.startDrawingQuads();
	        ts.addVertexWithUV(-7.0D, 2.0D, -2.0D, (double)var16, (double)var18);
	        ts.addVertexWithUV(-7.0D, 2.0D, 2.0D, (double)var17, (double)var18);
	        ts.addVertexWithUV(-7.0D, -2.0D, 2.0D, (double)var17, (double)var19);
	        ts.addVertexWithUV(-7.0D, -2.0D, -2.0D, (double)var16, (double)var19);
	        ts.draw();
	
	        for (int var23 = 0; var23 < 4; ++var23)
	        {
	            GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
	            GL11.glNormal3f(0.0F, 0.0F, var20);
	            ts.startDrawingQuads();
	            ts.addVertexWithUV(-8.0D, -2.0D, 0.0D, (double)var12, (double)var14);
	            ts.addVertexWithUV(8.0D, -2.0D, 0.0D, (double)var13, (double)var14);
	            ts.addVertexWithUV(8.0D, 2.0D, 0.0D, (double)var13, (double)var15);
	            ts.addVertexWithUV(-8.0D, 2.0D, 0.0D, (double)var12, (double)var15);
	            ts.draw();
	        }
			
	        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
	        GL11.glPopMatrix();
		}
		{
			EntityPlayer owner=hook.getOwner();
	        if (owner != null)
	        {
	    		double a=hook.isLeft()?0.5:-0.5;
				double y=Math.toRadians(owner.rotationYaw);
	            double d3 = owner.prevPosX + (owner.posX - owner.prevPosX) * (double)par9 + Math.cos(y)*a;
	            double d4 = owner.prevPosY + (owner.posY - owner.prevPosY) * (double)par9 - 1.0;
	            double d5 = owner.prevPosZ + (owner.posZ - owner.prevPosZ) * (double)par9 + Math.sin(y)*a;
	            //double d6 = owner != Minecraft.getMinecraft().thePlayer ? (double)owner.getEyeHeight() : 0.0D;
	            double d9 = hook.prevPosX + (hook.posX - hook.prevPosX) * (double)par9;
	            double d10 = hook.prevPosY + (hook.posY - hook.prevPosY) * (double)par9;
	            double d11 = hook.prevPosZ + (hook.posZ - hook.prevPosZ) * (double)par9;
	            double d12 = d3 - d9;
	            double d13 = d4 - d10;
	            double d14 = d5 - d11;
	            GL11.glDisable(GL11.GL_TEXTURE_2D);
	            GL11.glDisable(GL11.GL_LIGHTING);
	            ts.startDrawing(3);
	            ts.setColorOpaque_I(0);
	            int b2 = 255;
	            for (int i = 0; i <= b2; ++i)
	            {
	                float f12 = (float)i / (float)b2;
	                ts.addVertex(par2 + d12 * (double)f12, par4 + d13 * (double)f12, par6 + d14 * (double)f12);
	            }

	            ts.draw();
	            GL11.glEnable(GL11.GL_LIGHTING);
	            GL11.glEnable(GL11.GL_TEXTURE_2D);
	        }
		}
	}

	@Override
	public void doRender(Entity var1, double var2, double var4, double var6, float var8, float var9)
	{
		doRenderTDMGHock((EntityGearHook)var1, var2, var4, var6, var8, var9);
	}

	@Override
	protected ResourceLocation getEntityTexture(Entity entity) {
		// TODO 自動生成されたメソッド・スタブ
		return null;
	}

}
